package com.train.springboot.springboottrain.web;

import com.train.springboot.springboottrain.web.config.Abc;
import com.train.springboot.springboottrain.web.config.School;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class IndexController {
//http://localhost:8080/springboot/springboottrain/web
/*在 SpringBootController 中定义属性，并使用@Value 注解或者自定义配置值，并对其方法进行测试*/
/*
    @Value("${school.name}")
    private String schoolName;
    @Value("${websit}")
    private String websit;
*/

    @Autowired
    private School school;

    @Autowired
    private Abc abc;

    @RequestMapping(value = "/say")
    public @ResponseBody String say(/*String message*/){
//        return "Hello,SpringBoot!" + schoolName+":"+websit;
        return "school.name"+school.getName()+"----school.websit"+school.getWebsit() +"abc.name"+abc.getName()+"----abc.websit"+abc.getWebsit();

    }

    @RequestMapping(value = "/mapvalue")
    public @ResponseBody Map<String,Object> mapvalue(){
    Map<String,Object> reMap = new HashMap<String,Object>();
    reMap.put("message","SpringBoot Project");
    return reMap;
    }


    @RequestMapping(value = "/springBoot/jsp")
    public String jsp(Model model) {
        model.addAttribute("data","SpringBoot 前端使用 JSP 页面！");
        return "index";
    }



}
